package com.atguigu.datastream.test.day03;


import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import org.apache.kafka.clients.consumer.ConsumerConfig;

/**
 * ClassName: Flink_03_Source_Kafka
 * Package: com.atguigu.test.day03
 * Description:
 *           从kafka读取数据  老版本
 * @Author ChenJun
 * @Create 2023/4/9 19:10
 * @Version 1.0
 */
public class Flink_03_Source_Kafka {
    public static void main(String[] args) throws Exception {

        //1. 创建流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //2. 设置并行度
        env.setParallelism(1);

        // TODO 3. 从Kafka读取数据 1.13版本之前支持的API 在1.14已经过时了
        java.util.Properties properties = new java.util.Properties();
        properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"hadoop102:9092");
        properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG,"221109");
        properties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,"latest");

        DataStreamSource<String> streamSource = env.addSource(new FlinkKafkaConsumer<>("first", new SimpleStringSchema(), properties));

        //4. 打印
        streamSource.print();

        //5. 执行
        env.execute();
    }
}
